package com.xzc.web;

import com.xzc.utils.CookieUtils;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 徐州城
 * @version 1.0
 */
public class LoginServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        if ("xzc123".equals(username) && "123123".equals(password)){
            //登录成功，保存用户名为Cookie
            Cookie cookie = new Cookie("username",username);
            cookie.setMaxAge(60 * 60 * 24 * 7); //当前Cookie一周内有效
            resp.addCookie(cookie);
            System.out.println("登录成功!");
        }else {
            //登录失败
            System.out.println("登录失败!");
        }
    }
}
